// 导入axios
import axios from "axios";

// 创建axios实例
const service = axios.create({
    baseURL: "http://localhost:80",
    timeout: 300000
});

// 配置请求拦截器
service.interceptors.request.use(config => {
    console.log("请求拦截器被执行");
    console.log(config);
    // 添加请求头
    config.headers['token'] = window.sessionStorage.getItem('token');
    return config;
}, error => {
    console.log(error);
    return Promise.reject(error);
});

// 配置响应拦截器
service.interceptors.response.use(response => {
    console.log("响应拦截器被执行");
    console.log(response);
    return response;
}, error => {
    console.log(error);
    return Promise.reject(error);
});

export default service;